package cn.scxy.bookcity.controller;

import cn.scxy.bookcity.pojo.entity.Notice;
import cn.scxy.bookcity.pojo.vo.ImgsListItemVO;
import cn.scxy.bookcity.service.INoticeService;
import cn.scxy.bookcity.service.IOrdersService;
import cn.scxy.bookcity.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/notice")
@Api(tags = "公告")
@Slf4j
public class NoticeController {
    @Autowired
    private INoticeService service;
    @ApiOperation("根据商品id查询商品图片")
    @ApiOperationSupport(order = 300)
    @GetMapping("/list")
    public JsonResult<List<Notice>> list() {
        List<Notice> notice = service.list();
        return JsonResult.ok(notice);
    }
    @ApiOperation("显示公告")
    @ApiOperationSupport(order = 310)
    @ApiImplicitParam(name = "id", value = "类别id", required = true, dataType = "long")
    @PostMapping("/state/{id:[0-9]+}/enable1")
    public JsonResult<Void> setEnable1(@PathVariable Integer id) {
        log.debug("开始处理【启用公告】的请求，参数：{}", id);
        service.setEnable1(id);
        return JsonResult.ok();
    }

    // http://localhost:8080//9527/disable
    @ApiOperation("关闭公告")
    @ApiOperationSupport(order = 311)
    @ApiImplicitParam(name = "id", value = "类别id", required = true, dataType = "long")
    @PostMapping("/state/{id:[0-9]+}/disable1")
    public JsonResult<Void> setDisable1(@PathVariable Integer id) {
        log.debug("开始处理【禁用公告】的请求，参数：{}", id);
        service.setDisable1(id);
        return JsonResult.ok();
    }
    @ApiOperation("修改公告")
    @ApiOperationSupport(order = 311)
    @PostMapping("/update")
    public JsonResult<Void> update(Notice notice) {
        log.debug("开始处理修改请求，参数：{}");
        service.update(notice);
        return JsonResult.ok();
    }
    @ApiOperation("添加公告")
    @ApiOperationSupport(order = 311)
    @PostMapping("/insetNotice")
    public JsonResult<Void> insetNotice(Notice notice) {
        log.debug("开始处理修改请求，参数：{}");
        service.insetNotice(notice);
        return JsonResult.ok();
    }
    @ApiOperation("根据id删除公告")
    @ApiOperationSupport(order = 311)
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult<Void> deleteHot(@PathVariable Long id) {
        log.debug("根据id删除公告{}", id);
        service.delete(id);
        return JsonResult.ok();
    }

}
